package com.webwork.lims.warehouse.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.webwork.lims.util.Paging;
import com.webwork.lims.warehouse.dao.IncomeDao;
import com.webwork.lims.warehouse.dataobject.IncomeOrder;
import com.webwork.lims.warehouse.service.IncomeService;

@Service
public class IncomeServiceImpl implements IncomeService {

	@Autowired
	private IncomeDao incomeDao;

	@Override
	public int count(IncomeOrder queryObj) {
		return incomeDao.count(queryObj);
	}

	@Override
	public List<IncomeOrder> query(IncomeOrder queryObj) {
		return this.query(queryObj, new Paging(0, 0));
	}
	
	@Override
	public List<IncomeOrder> query(IncomeOrder queryObj, Paging paging) {
		return incomeDao.query(queryObj, paging.getCurrPage(), paging.getPageSize());
	}

	@Override
	public IncomeOrder get(String incomeId) {
		IncomeOrder queryObj = new IncomeOrder();
		queryObj.setIncomeId(incomeId);
		List<IncomeOrder> order = this.query(queryObj);
		if (order != null && order.size() > 0) {
			if (order.size() > 1) {
				System.out.println("存在不止一条记录!");
			} else {
				return order.get(0);
			}
		} else {
			System.out.println("找不到该入库单!");
		}
		return null;
	}

	@Override
	public void save(IncomeOrder order) {
		if (this.get(order.getIncomeId()) != null) {
			this.update(order);
		} else {
			this.insert(order);
		}
	}

	@Override
	public void insert(IncomeOrder order) {
		incomeDao.insert(order);
	}

	@Override
	public void update(IncomeOrder order) {
		incomeDao.update(order);
	}
	
}
